/*
 * Copyright 2008 the original author Ang Gao.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * 
 * TomcatServer.java 2008-11-25
 */
package ie.ucc.cs.anggao.finalproject.client.support.searchengine;

import ie.ucc.cs.anggao.finalproject.client.model.Query;
import ie.ucc.cs.anggao.finalproject.client.model.QueryEssay;
import ie.ucc.cs.anggao.finalproject.client.model.SearchEngine;
import ie.ucc.cs.anggao.finalproject.client.model.SearchEngineResult;
import ie.ucc.cs.anggao.finalproject.client.service.IRService;
import ie.ucc.cs.anggao.finalproject.client.service.IRServiceAsync;
import ie.ucc.cs.anggao.finalproject.client.ui.mainpanel.infopane.InfoPane;

import java.util.List;

import com.google.gwt.user.client.rpc.AsyncCallback;

/**
 * @author GaoAng
 * 
 */
public class TomcatServer{

	private IRServiceAsync service;
	
	private Query query; 
	
	public TomcatServer(InfoPane view) {
//		super(view, new SearchEngine("Google Search", "http://www.google.com"));
		service = IRService.IR.getInstance();
		query = new Query();
	}

	public void doIR(String q) {
//		service.getSEresult(new QueryEssay(q), new TomcatCallBack());
		service.getSEquery(new QueryEssay(q), new TomcatCallBack());
		
//		getView().clearResults();
	}

	private class TomcatCallBack implements AsyncCallback<Query>{

		public void onFailure(Throwable caught) {
			query = null;
		}

		public void onSuccess(Query result) {
			System.out.println(result.getQuery());
			query = result;
		}
		
	}

	public Query getQuery() {
		return query;
	}
	
	
	
	/*private class TomcatCallBack implements
			AsyncCallback<List<SearchEngineResult>> {

		public void onFailure(Throwable caught) {

		}

		public void onSuccess(List<SearchEngineResult> results) {
			for (SearchEngineResult SEresult : results) {

				System.out.println(SEresult.getTitle() + "\n");
				getView().addSearchResult(SEresult);
			}
		}
	}*/
}
